//
//  ReadBookVOrH_VC+PopTransWords.m
//  KidReading
//
//  Created by telen on 16/3/8.
//  Copyright © 2016年 刘赞黄Telen. All rights reserved.
//

#import "ReadBookVOrH_VC+PopTransWords.h"
#import "ConstDefine.h"


@interface ReadBookVOrH_VC()
@property(nonatomic,assign)TransView* transView;
@end

@implementation ReadBookVOrH_VC (PopTransWords)

ASSOCIATED(transView, setTransView, TransView*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

+ (void)load
{
    [self swizzleSelector:@selector(viewDidLoad) withSelector:@selector(viewDidLoad_poptrans)];
    [self swizzleSelector:@selector(applicationDidEnterBackground:) withSelector:@selector(applicationDidEnterBackground_poptrans:)];
}

- (void)viewDidLoad_poptrans
{
    [self viewDidLoad_poptrans];
    //
    //
    [mutex addMutexView:self.transView];
}


- (void)applicationDidEnterBackground_poptrans:(UIApplication *)application
{
    [self applicationDidEnterBackground_poptrans:application];
    //
    [self.transView unShow_must];
}

- (void)addTransView
{
    CGFloat words_w = 340/ratio_w;
    CGFloat words_h = 120/ratio_w;
    if ([DataProcessing shareSingle].deviceType == DevicesTypes_iPhone) {
        words_w *= 1.3;
        words_h *= 1.3;
    }
    CGFloat w = width_my;
    CGFloat h = height_my;
    CGPoint pt_show = CGPointMake(w*1/2, h*1/2);
    //
    TransView* transView = self.transView;
    if (!transView) {
        transView = [[TransView alloc] initWithFrame:CGRectMake(0, 0, words_w, words_h)];
        self.transView = transView;
        transView.delegate = self;
        [self.view addSubview:transView];
        transView.center = pt_show;
    }
    transView.pt_show = pt_show;
    transView.pt_unshowFollowView = [NSObject msgToTarget:self menthed:@"transBtn" refs:nil needReturnValue:YES];
    transView.transform = CGAffineTransformMakeScale(0, 0);
    transView.hidden = YES;
    transView.bookName = self.bookName;
}

- (NSNumber*)didTapSelfView_unShowTransView
{
    if (self.transView && !self.transView.hidden) {
        [self.transView unShow];
        return @(YES);
    }
    return nil;
}

- (NSNumber*)isTransViewShowing
{
    if(self.transView.isInShowing){
        return @(YES);
    }
    return nil;
}

- (NSNumber*)isTransViewWorking
{
    if(self.transView && (self.transView.hidden == NO || self.transView.isInShowing)){
        return @(YES);
    }
    return nil;
}

- (void)transViewMustUnshow
{
    [self.transView unShow_must];
}

@end
